package com.turing.comment.controller;

import com.alibaba.fastjson.JSONObject;
import com.turing.comment.service.CommentService;
import org.springframework.web.bind.annotation.*;
import result.Result;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * @author admin
 */
@RestController
public class CommentController {
    @Resource
    private CommentService commentService;


    /**
     * 40101评论列表(PC)
     */
    @GetMapping("cn/cnList")
    public Result getCnList(@RequestParam(value = "startTime", required = false) String startTime,
                            @RequestParam(value = "endTime", required = false) String endTime,
                            @RequestParam(value = "merchantName", required = false) String merchantName,
                            @RequestParam(value = "missionTitle", required = false) String missionTitle,
                            @RequestParam(value = "cusNickname", required = false) String cusNickname,
                            @RequestParam(value = "sortType", required = false) Integer sortType,
                            @RequestParam(value = "orderType") Integer orderType,
                            @RequestParam(value = "pageNum", required = false) Integer pageNum,
                            @RequestParam(value = "pageSize", required = false) Integer pageSize) {


        return commentService.getCnList(startTime, endTime, merchantName, missionTitle, cusNickname, sortType, orderType, pageNum, pageSize);
    }

    /** 40102评论详情(PC) */
    @GetMapping("/cn/geCnById")
    public Result geCnById(@RequestParam(value = "id", required = false) String id) {
        return commentService.geCnById(id);
    }
    /** 40103评论详情(手机) */
    @GetMapping("/cn/geCnByIdForPhone")
    public Result geCnByIdForPhone(@RequestParam(value = "id", required = false) String id) {
        return commentService.geCnByIdForPhone(id);
    }
    /** 测试验证通过token获取登录用户id */
    @GetMapping("/getCusId")
    public Result getCusId() {
        return commentService.getCusId();
    }

    /** 40107首页评论列表(手机) */
    @GetMapping("/cn/dashCommentList")
    public Result dashCommentList(@RequestParam(value = "cityId", required = false) String cityId,
                            @RequestParam(value = "sortType", required = false) Integer sortType,
                            @RequestParam(value = "orderType") Integer orderType,
                            @RequestParam(value = "pageNum", required = false) Integer pageNum,
                            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return commentService.dashCommentList(cityId, sortType, orderType, pageNum, pageSize);
    }
    /** 40104评论修改(PC) */
    @PatchMapping("/cn/cnEdit")
    public Result cnClose(@RequestParam(value = "commentId", required = true) String commentId,
                          @RequestParam(value = "adminScore", required = true) String adminScore,
                          @RequestParam(value = "commentAmount", required = true) String commentAmount,
                          @RequestParam(value = "cusInfo", required = false) String cusInfo) throws ParseException {
        return commentService.cnEdit(commentId,adminScore,commentAmount,cusInfo);
    }



    /** 40106关闭评论(PC) */
    @PatchMapping("/cn/cnClose")
    public Result cnClose(@RequestParam(value = "commentId", required = true) String commentId) throws ParseException {
        return commentService.cnClose(commentId);
    }

    /** 40108根据主键集合得到评论集合(手机) */
    @GetMapping("/cn/listCommentByIds")
    public Result listCommentByIds(@RequestParam(value = "ids", required = true) String[] ids){
        return commentService.listCommentByIds(ids);
    }


}
